package com.snopy.designPattern.create.prototype;

import com.snopy.designPattern.create.prototype.impl.A4paper;
import com.snopy.designPattern.create.prototype.impl.NapkinPaper;
import com.snopy.designPattern.create.prototype.impl.ToiletPaper;

import java.util.HashMap;
import java.util.Map;

/**
 * @author snopy
 * @version 1.0.0
 * @classname PaperCache
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/02 12:45
 */
public class PaperCache {
    private PaperCache(){
    }
    private  static Map<String,Paper> map = new HashMap<>();
    static {
        Paper paper1 = new A4paper();
        paper1.setId("1");
        paper1.setName("A4");
        paper1.size = 4;
        paper1.type = "A4";
        map.put(paper1.getId(),paper1);

        Paper paper2 = new NapkinPaper();
        paper2.setId("2");
        paper2.setName("餐巾纸");
        paper2.size = 3;
        paper2.type = "Napkin";
        map.put(paper2.getId(),paper2);

        Paper paper3 = new ToiletPaper();
        paper3.setId("3");
        paper3.setName("卫生纸");
        paper3.size = 2;
        paper3.type = "Toilet";
        map.put(paper3.getId(),paper3);
    }

    public static Paper getPaper(String id){
        Paper paper = map.get(id);
        return paper.clone();
    }
}
